﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Domain.Repositories;
using YAPACS.BusinessObjects.Exams;
using YAPACS.BusinessObjects.Managements.Exams;
using YAPACS.Organizations;

namespace YAPACS.RisServer.Controllers;
[Authorize]
[ApiController]
public class PatientFromController : AbpControllerBase
{
    private readonly ICurrentUserOrganization _currentUserOrganization;
    private readonly IRepository<PatientFrom, Guid> _patientFromRepository;
    private readonly IRepository<Exam, Guid> _examRepository;

    public PatientFromController(IRepository<PatientFrom, Guid> patientFromRepository,
                                 ICurrentUserOrganization currentUserOrganization,
                                 IRepository<Exam, Guid> examRepository)
    {
        _patientFromRepository = patientFromRepository;
        _currentUserOrganization = currentUserOrganization;
        _examRepository = examRepository;
    }

    [HttpGet("api/get-patient-froms")]
    public async Task<IActionResult> GetPatientFroms(Guid examId)
    {
        Exam exam = await _examRepository.GetAsync(examId);
        List<PatientFrom> list = await _patientFromRepository.GetListAsync(e => e.IsActive && e.Department == exam.Department);
        var result = list.OrderBy(e => e.Order).ThenBy(e => e.Name).Select(e => new
        {
            Label = e.Name,
            Value = e.Id
        });
        return Ok(result);
    }
}
